/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.app.param.buyer;

import com.shop.cereshop.commons.config.RsaProperties;
import com.shop.cereshop.commons.utils.RsaUtils;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 用户请求
 */
@Data
@ApiModel(value = "UserParam", description = "用户请求")
public class UserParam {

    /**
     * 验证码
     */
    @ApiModelProperty(value = "验证码")
    private String verificationCode;

    /**
     * 验证码
     */
    @ApiModelProperty(value = "老手机号验证码")
    private String oldVerificationCode;

    /**
     * 手机号
     */
    @ApiModelProperty(value = "手机号")
    private String phone;

    /**
     * 密码
     */
    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "旧密码")
    private String oldPassword;

    /**
     * 新密码
     */
    @ApiModelProperty(value = "新密码")
    private String newPassword;

    public UserParam decrypt() throws Exception {
        UserParam res = this;
        if (StrUtil.isNotBlank(this.password)) {
            res.setPassword(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,this.password));
        }
        if (StrUtil.isNotBlank(this.phone)) {
            res.setPhone(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,this.phone));
        }
        if (StrUtil.isNotBlank(this.oldPassword)) {
            res.setOldPassword(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,this.oldPassword));
        }

        return res;
    }
}
